package my.ms;

import com.alibaba.fastjson.JSONObject;

import java.math.BigDecimal;

public class Test {

    public static void main(String[] args) {
        BigDecimal a = new BigDecimal(10000.995461);
        BigDecimal b = new BigDecimal(10000);
        System.out.println(a.compareTo(b));
        System.out.println(a.toPlainString());

        try{
            //xd_gateway库partner表aesKey，md5Salt
            String aseKey = "B8OevT5wAL94xmRQGVm4Tw==";// aes 对称密钥
            String salt="8aa16b3b-fbbd-424e-badf-788ccce0d1b1";// 盐

            //请求体
            JSONObject body = new JSONObject();
            body.put("openId","coopr_jinshan338758814168256512");
            body.put("inChannel","coopr_jinshan");
            body.put("productCode","YKD_001");
            //body.put("coApplCde","12345678987654321");

            //请求头
            JSONObject head = new JSONObject();
            head.put("corp_code","coopr_jinshan");
            head.put("timestamp","1589250222384");
            head.put("business_code","YKD_QueryProductAmount");
            //head.put("business_code","YKD_QueryApplyResult");

            //请求data
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("body", body);
            jsonObject.put("head", head);

            // 原报文
            String srcData = jsonObject.toJSONString();
            System.out.println("解密前报文:"+srcData);

            // 加密
            String encryptData = AES.encrypt(srcData, AES.generateKey(Base64.decode(aseKey)));
            // 加签
            String sign = MD5.encodeByMd5WithSalt(srcData,salt);

            // 解密
            String decryptData = AES.decrypt(encryptData, AES.generateKey(Base64.decode(aseKey)));
            System.out.println("解密后得到的报文:"+decryptData);
            // 验签
            String signFormDecryptData = MD5.encodeByMd5WithSalt(decryptData, salt);
            if(signFormDecryptData.equalsIgnoreCase(sign)){
                System.out.println("验签通过");
            }

            System.out.println("data(AES加密后的数据):");
            System.out.println(encryptData);
            System.out.println("mac(MD5加签后的数据):");
            System.out.println(sign);

        } catch (Exception e){
            e.printStackTrace();
        }
    }
}
